@extends('common.admin_template')

@section('content')
    <?php
        $status=isset($_GET['status'])?$_GET['status']:'';
    ?>
    <link rel="stylesheet" type="text/css" href="{{asset('css/daterangepicker.css')}}" />
    <div class="boxWidth">
        @include('common.notice_msg')
        <div class="row searchLine">
            <div class="col-xs-6 ">
                选择时间：<input id="datefilter" type="text" name="datefilter" readonly  class="searchSelect" style="text-align: center" value="{{isset($_GET["start"])?$_GET["start"].'/'.$_GET["end"]:''}}">
                <select id="cat" class="searchSelect">
                    <option value="not">全部订单</option>
                    <option value="0"  @if($status==='0') selected="selected"  @endif>未付款</option>
                    <option value="1" @if($status==='1') selected="selected"  @endif>已付款</option>
                    <option value="2" @if($status==='2') selected="selected"  @endif>已取消</option>
                </select>
                <button id="orderStatus" class="btn btn-default searchBtn">筛选</button>
                <a href="{{asset('excel/export?export=order'.(isset($_GET["start"])?'&start='.$_GET["start"].'&end='.$_GET["end"]:'').($status!==''?'&status='.$status:'').(isset($_GET["page"])?'&page='.$_GET["page"]:''))}}"><button class="btn btn-default searchBtn">下载</button></a>
            </div>
            <div class="col-xs-6 searchInput">
                <input type="text" placeholder="请输入订单号" id="searchInput">
                <button class="btn btn-default searchBtn" id="searchCon">搜索</button>
            </div>
        </div>
        <table class="table table-hover adminTableBg">
            <thead>
            <tr>
                <th class="col-xs-2">订单号</th>
                <th class="col-xs-3">订单内容</th>
                <th class="col-xs-1">价格</th>
                <th class="col-xs-1">购买者</th>
                <th class="col-xs-1">状态</th>
                <th class="col-xs-1">配送</th>
                <th class="col-xs-2">时间</th>
                <th class="col-xs-1">操作</th>
            </tr>
            </thead>
            <tbody>
            <?php $metaName = ['未','已'];$statusName = ['未付款','已付款','已取消']; ?>
            @foreach($Orders as $g)
                <tr>
                    <th class="col-xs-2 itemTd">{{$g->trade}}</th>
                    <th class="col-xs-3 itemTd">{{$g->body}}</th>
                    <th class="col-xs-1 itemTd">{{$g->total}}</th>
                    <th class="col-xs-1 itemTd">{{$g->user}}</th>
                    <th class="col-xs-1 itemTd">{{$statusName[$g->status]}}</th>
                    <th class="col-xs-1 itemTd">{{$metaName[$g->meta]}}配送</th>
                    <th class="col-xs-2 itemTd">{{$g->created_at}}</th>
                    <th class="col-xs-1 itemTd">
                        <a href="{{url('admin/orders/view',['id' => $g->id])}}"><span >查看</span></a>
                    </th>
                </tr>
            @endforeach
            </tbody>
        </table>
        <div class="pull-right">
            @if(!isset($_GET["start"]))
                <?php
                    $s=isset($_GET['s'])?$_GET['s']:'';
                    if($s){
                        $url = ['s' => $s];
                    }elseif($status){
                        $url = ['status' => $status];
                    }else{
                        $url = [];
                    }
                ?>
                {!! $Orders->appends($url)->render() !!}
            @endif
        </div>
    </div>
@stop
@section('js')
    <script src="{{asset('js/moment.min.js')}}"></script>
    <script src="{{asset('js/daterangepicker.js')}}"></script>
    <script>
        (function () {
            $('input[name="datefilter"]').daterangepicker({
                autoUpdateInput: false,
                locale: {
                    applyLabel: '确定',
                    cancelLabel: '清除',
                    fromLabel : '起始时间',
                    toLabel : '结束时间',
                    daysOfWeek : [ '日', '一', '二', '三', '四', '五', '六' ],
                    monthNames : [ '一月', '二月', '三月', '四月', '五月', '六月',
                        '七月', '八月', '九月', '十月', '十一月', '十二月' ],
                    firstDay : 1
                }
            });
            $('input[name="datefilter"]').on('apply.daterangepicker', function(ev, picker) {
                $(this).val(picker.startDate.format('YYYY-MM-DD') + '/' + picker.endDate.format('YYYY-MM-DD'));
            });

            $('input[name="datefilter"]').on('cancel.daterangepicker', function(ev, picker) {
                $(this).val('');
            });
            $('#searchCon').on('click',function () {
                var url = $('#searchInput').val().replace(/(^\s*)|(\s*$)/g, "");
                if(url){
                    window.location.href= "{!! url('admin/orders?s=') !!}"+url;
                }else{
                    window.location.href= "{!! url('admin/orders') !!}"
                }
            });
            $('#orderStatus').on('click',function () {
                var t = $('#datefilter').val(),cat = $('#cat').val(),url = '{!! url('admin/orders?') !!}';
                if(cat!='not'){
                    url += 'status='+cat+'&';
                }
                if(t){
                    var tArr = t.split('/'),start = tArr[0], end = tArr[1];
                    url += 'start='+start+'&'+'end='+end;
                }
                window.location.href= url
            });
        })()
    </script>
@stop